home *** CD-ROM | disk | FTP | other *** search
- Path: geraldo.cc.utexas.edu!usenet
- From: Richard Kilgore <rkilgore@lore.ece.utexas.edu>
- Newsgroups: comp.lang.c++
- Subject: Re: So I have this pointer-to-member function...
- Date: 1 Feb 1996 19:18:03 GMT
- Organization: The University of Texas at Austin, Austin, Texas
- Message-ID: <4er3lb$g63@geraldo.cc.utexas.edu>
- References: <d4c1.smail.smayo@tiac.net> <310BD244.331C@gsfc.nasa.gov>
- NNTP-Posting-Host: lore.ece.utexas.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; Linux 1.3.18 i586)
- X-URL: news:310BD244.331C@gsfc.nasa.gov
-
- Scott Mayo wrote:
- > The compiler will have none of it. It takes one glance at the static struct
- > {char*name; void (C::*f)();} list[] = {"A", C::A}; and has a hissy fit at the
- > attempt to assign initializers. It's fine outside the class definition; it
- > won't work inside.
-
- Yes, C++ doesn't allow you to initialize any data members inside the class
- declaration, b/c it views any members inside as declarations, not definitions.
- Like an extern. Even if you decided to leave it uninitialized and just set
- its contents later somewhere, the linker would complain that it can't find a
- definition for "list".
-
- I suggest you give the structure a name, and then inside the class declaration
- you can use something like:
-
- struct mystruct {char*name; void (C::*f)();};
- struct mystruct list[];
-
- And then in your .cc file, you can initialize it with something like:
-
- struct C::mystruct C::list[] = { <whatever> };
-
- There might be a shortcut to avoid the struct name if you don't want it, but
- as long as you get the idea about the initialization. No matter what kind of
- static data member you have, you'll have to define and initialize it in the
- cc file (or .cpp if your a windoze user).
-
- - rick
-
- --
- Richard B. Kilgore
- Grad Student, University of Texas at Austin
- WWW URL: http://lore.ece.utexas.edu/~rkilgore/
- E-mail rkilgore@lore.ece.utexas.edu
-
-